<template>
  <div class="list">
    <!-- 这是列表{{ value }} -->
    <div class="listItem" v-for="item in list" :key="item.id">
      <div class="item-img">
        <img :src="item.goodsShow[0].url" />
      </div>
      <div class="info">
        <div class="title ele fz16">
          {{ item.goods_name }}
        </div>
        <div class="last-title ele fz12">
          {{ item.info }}
        </div>
        <div class="price">
          <span class="priceNew fz18"
            >￥{{ item.goodsStandard[0].cost_price }}</span
          >
          <span class="fz12 priceOld"
            >原价：<del>￥{{ item.goodsStandard[0].goods_price }}</del></span
          >
          <van-button
            class="button"
            color="linear-gradient(to right,  #FF5BF4,#622CCC)"
            @click="goProduce(item.id)"
          >
            去购买
            <!-- {{ typeId }} -->
          </van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { getGoodList } from '@/api/index.js'

export default {
  computed: {
    ...mapState('product', ['productItem'])
  },
  props: ['typeId'], //获取到点击的类目1-2-3
  created() {
    this.getGoodList() // 获取商品列表
    // console.log(this.typeId) //根据id展示目录下的数据
  },
  data() {
    return {
      list: [],
      page: 1,
      pageSize: 10
    }
  },
  methods: {
    goProduce(id) {
      // 跳转视频页
      this.$router.push({ name: 'product', query: { id } })
    },

    async getGoodList() {
      // 获取商品列表
      try {
        const res = await getGoodList({
          goodsType: this.typeId,
          page: this.page,
          pageSize: this.pageSize
        })
        this.list = res.data.list
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.list {
  background: #f7f6fb;
  padding: 16px;
  .listItem {
    margin-bottom: 16px;
    width: 343px;
    height: 377px;
    background: #ffffff;
    box-shadow: 0px 4px 12px 0px rgba(31, 13, 68, 0.04);
    border-radius: 8px;
    .item-img {
      width: 343px;
      height: 260px;
      border-radius: 8px 8px 0px 0px;
      img {
        width: 100%;
        height: 100%;
      }
      //   background-color: #ff3040;
    }
    .info {
      padding: 12px;
      .title {
        width: 319px;
        // height: 22px;
        // line-height: 22px;
        margin-bottom: 6px;
      }
      .last-title {
        height: 17px;
        line-height: 17px;
        margin-bottom: 15px;
      }
      .price {
        position: relative;
        display: flex;
        align-items: center;
        // line-height: 14px;
        .priceNew {
          padding-right: 6px;
        }
        .priceOld {
          position: relative;
          top: 2px;
        }
        .button {
          position: absolute;
          right: 0;
          width: 76px;
          height: 32px;
          box-shadow: 0px 2px 6px 0px rgba(98, 44, 204, 0.3);
          border-radius: 16px;
        }
      }
    }
  }
}
</style>
